# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/15 21:32
# @Author   : Robot-Zsj
"""
description:

i:
4
1 4
2 5
7 9
14 18

o:
1 5
7 9
14 18
"""


def merge(roomTimes):
    roomTimes.sort(key=lambda x: x[0])

    ans = []

    pre = roomTimes[0]
    for i in range(1, len(roomTimes)):
        cur = roomTimes[i]

        if cur[0] <= pre[1]:
            pre[1] = max(pre[1], cur[1])
        else:
            ans.append(pre)
            pre = cur

    ans.append(pre)

    return ans


n = int(input())

roomTimes = []

for _ in range(n):
    roomTimes.append(list(map(int, input().split())))

for start, end in merge(roomTimes):
    print(f"{start} {end}")
